package org.sabeot.enlistme.service.impl;

import java.util.List;

import javassist.tools.framedump;

import org.hibernate.exception.ConstraintViolationException;
import org.sabeot.enlistme.hibernate.dao.UserDAO;
import org.sabeot.enlistme.hibernate.dto.UserDTO;
import org.sabeot.enlistme.service.UserService;
import org.sabeot.enlistme.utils.exceptions.DatabaseException;
import org.sabeot.enlistme.utils.exceptions.ExceptionCategory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service("userService")
public class UserServiceImpl implements UserService {

	@Autowired
	UserDAO userDao;

	@Override
	public UserDTO findByUserId(Long id) {
		// TODO Auto-generated method stub
		return null;
	}

	public boolean createNewUser(String login, String email, boolean isActive) throws DatabaseException {
		if(login == null || login.isEmpty())
			return false;
		
		if(email == null || email.isEmpty())
			return false;
		
		try{
		userDao.createNewUser(login, email, isActive);
		}catch(ConstraintViolationException e){
			e.printStackTrace();
			throw new DatabaseException(ExceptionCategory.OBJECT_ALREADY_EXSITS_IN_DB, e.getLocalizedMessage());

		}
		return true;
	}

	public void deleteUser(Long id) {
		// TODO Auto-generated method stub

	}

	@Override
	public List<UserDTO> findUsers(String login) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<UserDTO> getAllUsers() {
		return userDao.findAllUsers();
	}

}
